<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta charset="UTF-8">
    <title>潮人电商后台</title>
    <link rel="stylesheet" href="css/public.css"/>
    <link rel="stylesheet" href="css/style.css"/>
    <script type="text/javascript" src="/bootstarp/js/jquery-1.8.3.js"></script>
</head>
<body>
<!--头部-->
<header class="publicHeader">
    <h1>潮人管理系统</h1>

    <div class="publicHeaderR">
        <p><span>下午好！</span><span style="color: #fff21b"  th:text="${session.user.UAccount}"> Admin</span> , 欢迎你！</p>
        <a href="/logout">退出</a>
    </div>
</header>
<!--时间-->
<section class="publicTime">
    <span id="time">2015年1月1日 11:11  星期一</span>
    <a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
</section>
<!--主体内容-->
<section class="publicMian ">
    <div class="left">
        <h2 class="leftH2"><span class="span1"></span>功能列表 <span></span></h2>
        <nav>
            <ul class="list">
                <li ><a href="/productPage">商品管理</a></li>
                <li><a href="/orderFromPage">订单管理</a></li>
                <li><a href="/gongyingPage">供应商管理</a></li>
                <li><a href="/yuangongPage">员工管理</a></li>
                <li><a href="/passwordPage">密码修改</a></li>
                <li><a href="/logout">退出系统</a></li>
            </ul>
        </nav>
    </div>
    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>商品管理页面 >> 商品修改页面</span>
        </div>
        <div class="providerAdd">
            <form action="#" id="omg">
                <!--div的class 为error是验证错误，ok是验证成功-->
                 <input type="hidden" id="proId" name="proId"/>
                 <input type="hidden" name="proImage" id="img"/>
                <div class="">
                    <label for="proKucun">商品库存：</label>
                    <input type="text" name="proKucun" id="proKucun" placeholder="322"/>
                    <span>*</span>
                </div>
                <div>
                    <label for="proName">商品名称：</label>
                    <input type="text" name="proName" id="proName" placeholder="123"/>
                    <span >*</span>
                </div>
				
               <div>
                  <label >供应商：</label>
                  <select name="gId" id="gId">
                      <option value="">--请选择供应商--</option>


              
                  </select>
                  <span>*</span>
              </div>
			  
                <div>
                    <label for="proPrice">商品价格：</label>
                    <input type="text" name="proPrice" id="proPrice" placeholder="22"/>
                    <span>*</span>
                </div>
				
                 <div>
                   <label >是否上架：</label>
                   <select name="proPutaway" id="proPutaway">
                       <option value="">--请选择--</option>
                       <option value="0">上架</option>
                       <option value="1">不上架</option>
               
                   </select>
                   <span>*</span>
               </div>
			   
			    <div>
			       <label for="proImage">预览图修改：</label>
			       <input type="file" name="proImage" id="proImage" required onchange="qq()"/>
			       <img src=""  id="im"/>
			   </div>
               
               
                <div class="providerAddBtn">
                    <!--<a href="#">保存</a>-->
                    <!--<a href="billList.html">返回</a>-->
                    <input type="button" value="保存" onclick="xiugai()"/>
                    <input type="button" value="返回" onclick="history.back(-1)"/>
                </div>
            </form>
        </div>

    </div>
</section>
<footer class="footer">
</footer>
<script src="js/time.js"></script>


<script>

     $(function () {

          $.ajax({

              url:"/selectAll",
              type:"get",
              success:function (data) {

                  if (data.gongYings!=null){

                      alert("下拉框查询成功");

                      parse(data.gongYings);
                  }
              }
          })
     })

    function parse(data) {

         for (var index in data) {

             var aa =data[index];

             $("#gId").append(

                 "<option value="+aa.gid+">"+aa.gname+"</option>"
             )
         }

    }


     window.onload=function () {
         var search = location.search;

         var s = search.substring(1);
         var strings = s.split("&");
         for (var index in strings){
             var strings1 = strings[index].split("=");
             var name = strings1[0];
             var value = strings1[1];


               if (name=="proName"){

                   value=decodeURI(value);
               }

               if (name=="proImage"){
                   $("#im").prop("src","/img/"+value);

                   $("#proImage").val(value);
               }

               if (name=="proPutaway"){

                    value=="是"?"0":"1";
               }
             var elementById = document.getElementById(name);
             elementById.setAttribute("value",value);

         }


     }


     function qq() {

          var forData = new FormData();
          var file =$("#proImage")[0].files[0];
          forData.append("file",file);

          $.ajax({

              url:"/shangchuang",
              type:"post",
              contentType:false,
              processData:false,
              data:forData,
              success:function (data) {

                  if (data.code==4){
                      alert("上传失败");
                  }

                  if (data.code==0){

                      alert("上传成功");
                      $("#img").val(data.data);
                  }

                  $("#im").prop("src","/img/"+data.data);
              }

          })
     }


      function xiugai() {

           $.ajax({

               url:"/modifyProduct",
               type:"post",
               data:$("#omg").serialize(),
               success:function (data) {

                    if (data.code==4){
                        alert("修改失败");
                    }

                    if (data.code==0){

                        alert("修改成功");
                        location.href="http://localhost:8080/productPage";
                    }
               }
           })
      }
</script>

</body>
</html>